package day2;

import org.junit.Test;

import java.util.Scanner;

public class SwitchDemo {
    //   >=90   <=100   优秀
    //   >=80    <90       良好
    //   >=70    <80       一般
    //   >=60    <70      及格
    //   <60                    不及格
   // Ctrl+Alt+L 格式化代码
    @Test
    public void test1() {
        int score = 99;
        switch (score / 10) {
            case 10:
            case 9:
                System.out.println("优秀");
                break;
            case 8:
                System.out.println("良好");
                break;
            case 7:
                System.out.println("一般");
                break;
            case 6:
                System.out.println("及格");
                break;
            case 5:
            case 4:
            case 3:
            case 2:
            case 1:
            case 0:
                System.out.println("不及格");
                break;
            default:
                System.out.println("default");
                break;
        }
    }

    @Test
    public void test2() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入成绩");
        int score = scanner.nextInt();
        // 对于非法的输入，使用卫语句
        if (score < 0 || score > 100) {
            System.out.println("这是一个非法的输入");
            return;
        }
        // 其他非法操作 return

        switch (score / 10) {
            case 10:
            case 9:
                System.out.println("优秀");
                // break;
            case 8:
                System.out.println("良好");
                break;
            case 7:
                System.out.println("一般");
                break;
            case 6:
                System.out.println("及格");
                break;
            default:
                System.out.println("不及格");
                break;
        }
    }


}

